js 集合中删除某个属性name | 您所在的位置:网站首页 › js map 遍历删除 › js 集合中删除某个属性name |
1.tableData集合种,删除数组的某个属性,需要用forEach遍历tableData集合,在遍历过程中, 直接调用delete item.name, 就可以把集合中的name属性删除掉 var tableData=[ { name:"小武", value:"a" }, { name:"小刘", value:"b" } ] tableData.forEach(item => { delete item.name; }); console.log(tableData);还有一种方法,map种,name属性删除 const data = tableData.map(item => { const { name, ...rest } = item; return rest; }); console.log(data);2. 删除某一行,传进来一个id,根据id不等原则获取 delSingleGoods(goods){ console.log(goods); this.tableData=this.tableData.filter(o => o.goodsId !=goods.goodsId); }3. 获取index lengend = res.map(function (value, index) { return index; });4. some(),every()循环遍历,统计数组是否满足某个条件 1> some方法是只要一个成员的返回值是true,则整个some方法的返回值就是true,否则返回false。 var arr = [1, 2, 3, 4, 5]; arr.some(function (elem, index, arr) { return elem >= 3; }); // true2> 而every方法则相反,所有成员的返回值都是true,整个every方法才返回true,否则返回false。两相比较,some()只要有一个是true,便返回true;而every()只要有一个是false,便返回false. var arr = [1, 2, 3, 4, 5]; arr.every(function (elem, index, arr) { return elem >= 3; }); // false5. reduce(),reduceRight()方法可依次处理数组的每个成员 [1, 2, 3, 4, 5].reduce(function (a, b) { console.log(a, b); return a + b; }) // 1 2 // 3 3 // 6 4 // 10 5 //最后结果:156. angular6 *ngFor获取index 作业{{i+1}} |
CopyRight 2018-2019 实验室设备网 版权所有 |